package com.shujia.hbase.api;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Put;

import java.io.IOException;

public class Demo2Tablequery {
    public static void main(String[] args) throws IOException {

        /**
         * 1、创建连接   和zk建立连接
         * 2、
         *
         */

        //创建hadoop配置文件对象
        Configuration configuration = new Configuration();

        //指定zk地址
        configuration.set("hbase.zookeeper.quorum", "node1:2181,node2:2181,node3:2181");

        //建立连接   和zk的连接
        HConnection connection = HConnectionManager.createConnection(configuration);


        //获取表实例
        HTableInterface student = connection.getTable("student");


        //创建put对象    指定rowkey
        Put put = new Put("001".getBytes());

        //增加一列
        put.add("info".getBytes(), "name".getBytes(), "zhsngsan".getBytes());


        //插入数据
        student.put(put);


        //关闭连接
        connection.close();


    }
}
